﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using QLLUONG.DAL;
using QLLUONG.DTO;
namespace QLLUONG.BLL
{
    class LuongBLL
    {
        DataClasses1DataContext DB = new DataClasses1DataContext();
        public List<LUONG> Show()
        {
            return DB.LUONGs.ToList();
        }
        public bool Insert(Luong Luong)
        {
            LUONG L = new LUONG();
            try
            {
                L.MANV = Luong.Msnv;
                L.TENCV = Luong.Tencv;
                L.PHUCAP = Luong.Phucap;
                L.LUONGTAMUNG = Luong.Luongtam;
                L.SONGAYCONG = Luong.Songaycong;
                L.THUNHAPKHAC = Luong.Thunhapkhac;
                L.BAOHIEM = Luong.Baohiem;
                DB.LUONGs.InsertOnSubmit(L);
                DB.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool Update(Luong Luong)
        {
            LUONG L = DB.LUONGs.Where(l => l.MANV == Luong.Msnv).FirstOrDefault();
            try
            {
                
                L.TENCV = Luong.Tencv;
                L.PHUCAP = Luong.Phucap;
                L.LUONGTAMUNG = Luong.Luongtam;
                L.SONGAYCONG = Luong.Songaycong;
                L.THUNHAPKHAC = Luong.Thunhapkhac;
                L.BAOHIEM = Luong.Baohiem;
                DB.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        public double BaoHiem(String MANV)
        {
            LUONG L = DB.LUONGs.Where(l => l.MANV == MANV).FirstOrDefault();
            return L.BAOHIEM;
        }
        public double ThuNhapKhac(String MANV)
        {
            LUONG L = DB.LUONGs.Where(l => l.MANV == MANV).FirstOrDefault();
            return L.THUNHAPKHAC;
        }
        public int NgayCong(String MANV)
        {
            LUONG L = DB.LUONGs.Where(l => l.MANV == MANV).FirstOrDefault();
            return L.SONGAYCONG;
        }
        public bool Delete(String MaNV)
        {
            LUONG L = DB.LUONGs.Where(l => l.MANV == MaNV).FirstOrDefault();
            try
            {

                DB.LUONGs.DeleteOnSubmit(L);
                DB.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
        public bool KiemTraLuong(String MSNV)
        {
            var List = from LUONG in DB.LUONGs
                       where LUONG.MANV.Contains(MSNV)
                       select LUONG;
            if (List.Any())
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public List<LUONG> SearchLuong(double Luong)
        {
            var List = from LUONG in DB.LUONGs
                       where LUONG.LUONGTAMUNG > Luong
                       select LUONG;
            return List.ToList();
        }
        public List<LUONG> SearchLuong(String Nghach)
        {
            var List = from LUONG in DB.LUONGs
                       where LUONG.TENCV.Contains(Nghach)
                       select LUONG;
            return List.ToList();
        }
    }
}
